<template>
  <section class="app-main">
    <transition name="fade" mode="out-in">
      <breadcrumb class="breadcrumb" v-if="titleShow"></breadcrumb>
      <div class="title" v-else>{{ title }}</div>
    </transition>
    <transition name="fade-transform" mode="out-in">
      <router-view :key="key" />
    </transition>
  </section>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import { EventBus } from '@/utils/eventBus';
export default {
  name: 'AppMain',
  components: {
    Breadcrumb,
    Hamburger
  },
  data() {
    return {
      titleShow: false
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ]),
    key() {
      return this.$route.path
    },
    title() {
      return this.$route.meta.title
    }
  },
  created() {
    EventBus.$on('siblingEvent', this.handleSiblingEvent);
  },
  beforeDestroy() {
    EventBus.$off('siblingEvent', this.handleSiblingEvent);
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    handleSiblingEvent(data) {
      this.titleShow = data
    }
  }
}
</script>

<style scoped>
.app-main {
  /*50 = navbar  */
  min-height: calc(100% - 80px);
  width: 100%;
  position: relative;
  padding: 0 20px;
  margin-top:80px;
  background-color: #fff;
  overflow-y: scroll;
}
.fixed-header+.app-main {
  padding-top: 50px;
}
</style>

<style lang="scss" scoped>
.breadcrumb {
  display: flex;
  align-items: center;
  margin-top: 20px;
  transition: all .3s ease-in-out; /* 添加滑动动画 */
  will-change: all;
}
.title {
  padding-bottom: 0;
  font-size: 24px;
  font-weight: 600;
  color: #224DB0;
  text-align: center;
  height: 100px;
  line-height: 100px;
  position: relative;
  background: url('../../assets/pic/title.png') no-repeat;
  background-size: 100% 100%;
  transition: all .3s ease-in-out; /* 添加滑动动画 */
  will-change: all;
}
.login-container {
  height: 100%;
}
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 15px;
  }
}
</style>
